<!-- 普通模式演示(vue) -->
<template>
	<view class="content">
		<z-paging ref="paging" fixed @query="queryList" :list.sync="dataList">
			<u-tabs slot="top" active-color="#f44c01" :list="list" :current="tabIndex" @change="tabChange"></u-tabs>
			<view class="list">
				<u-swipe-action :show="item.show" :index="index" v-for="(item, index) in dataList" :key="item.id"
					@click="click" @open="open" :options="options">
					<view class="houseList" @click="routeTo(item)">
						<u-image v-if="item.pic" width="220rpx" height="160rpx" :src="item.pic">
						</u-image>
						<view class="cont">
							<view style="display: flex;flex-direction: row;flex: 1;align-items: flex-start;">
								<text class="title">{{item.name}}</text>
							</view>
							<text class="info">{{item.createTime}}</text>
						</view>
					</view>
				</u-swipe-action>
			</view>
		</z-paging>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '招聘信息',
					type: '6'
				}, {
					name: '人才信息',
					type: '7'
				}, {
					name: '房源信息',
					type: '1'
				}, {
					name: '物品信息',
					type: '3'
				}, {
					name: '农林牧渔',
					type: '2'
				}, {
					name: '生意转让',
					type: '8'
				}, {
					name: '需求打听',
					type: '5'
				}, {
					name: '本地推广',
					type: '4'
				}, {
					name: '品质好车',
					type: '10'
				}, {
                 					name: '商家店铺',
                 					type: '9'
                 				}],
				dataList: [],
				tabIndex: 0,
				search: {
					type: 'job',
					pageNum: 1,
				},
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}]
			}
		},
		methods: {
			tabChange(index) {
				this.tabIndex = index;
				this.search.type = this.list[index].type;
				this.$refs.paging.reload();
			},
			queryList(pageNo, pageSize) {
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//通过this.$refs.paging.complete(请求回来的数组);将请求结果传给z-paging
				this.search.pageNum = pageNo;
				this.$u.get('/tc/queryCollect', this.search).then(res => {
					this.$refs.paging.complete(res)
				}).catch(err => {
					this.$refs.paging.complete(false)
				})
			},
			click(index, index1) {
				if (index1 == 0) {
					this.$u.post('/tc/addCollect', {
						type: this.search.type,
						objId: this.dataList[index].objId,
						title: this.dataList[index].title,
					}).then(res => {
						this.dataList.splice(index, 1);
					})
				}
			},
			open(index) {
				this.dataList[index].show = true;
				this.dataList.map((val, idx) => {
					if (index != idx) this.dataList[idx].show = false;
				})
				this.$forceUpdate()
			},
			routeTo(item) {
				console.log(item)
				switch (this.search.type) {
					case '6':
						this.$u.route('/pagesIndex/jobmain/jobmain', {
							id: item.objId
						})
						break;
					case '7':
						this.$u.route('/pagesIndex/resumemain/resumemain', {
							id: item.objId
						})
						break;

					case '1':
						this.$u.route('/pagesIndex/housemain/housemain', {
							id: item.objId
						})
						break;
					case 'car':
						this.$u.route('/pagesIndex/carmain/carmain', {
							id: item.objId
						})
						break;
					case '3':
						this.$u.route('/pagesIndex/goodsmain/goodsmain', {
							id: item.objId
						})
						break;
					case '2':
						this.$u.route('/pagesIndex/farmingmain/farmingmain', {
							id: item.objId
						})
						break;
					case '8':
						this.$u.route('/pagesIndex/transfermain/transfermain', {
							id: item.objId
						})
						break;
					case '4':
						this.$u.route('/pagesIndex/promotemain/promotemain', {
							id: item.objId
						})
						break;
					case '9':
						this.$u.route('/pagesFind/storemain/storemain', {
							id: item.objId
						})
						break;
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.houseList {
		display: flex;
		flex-direction: row;
		padding: 20rpx;
		background-color: white;
		border-bottom: 1rpx solid #e6e6e6;

		.cont {
			display: flex;
			flex-direction: column;
			flex: 1;
			margin-left: 20rpx;

			.title {
				font-size: 32rpx;
				color: #333333;
				flex: 1;
				font-weight: 600;
				word-break: break-all;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
				overflow: hidden;
			}

			.info {
				font-size: 26rpx;
				color: #999999;
				margin-top: 20rpx;
			}
		}
	}
</style>
